﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="添加用户推荐的视频" %>

<script runat="server">
	TUserRecommend theRecommend = null;
	protected void Page_Load(object sender, EventArgs e)
	{
		try
		{
			int id = int.Parse(Request["id"]);
			using (TDataContext db = new TDataContext())
			{
				theRecommend = db.TUserRecommends.First(ur => ur.Id == id);
			}
		}
		catch
		{
			Response.StatusCode = 404;
			Response.End();
			return;
		}

		if (!IsPostBack)
		{
			txtTitle.Text = theRecommend.Title;
			txtDescription.Text = theRecommend.Description;
			txtSource.Text = theRecommend.Source;
			txtEmbeddedCode.Text = theRecommend.EmbeddedCode;
			txtUserName.Text = theRecommend.UserName;
			txtUserUrl.Text = theRecommend.UserUrl;

			lnkSource.NavigateUrl = theRecommend.Source;
			lnkUserUrl.NavigateUrl = theRecommend.UserUrl;
		}
	}
	
	protected void btnAdd_Click(object sender, EventArgs e)
	{
		using (TDataContext db = new TDataContext())
		{
			TUserRecommend commend = db.TUserRecommends.First(ur => ur.Id == theRecommend.Id);

			TVideo video = new TVideo()
			{
				Title = txtTitle.Text.Trim(),
				Description = txtDescription.Text.Trim(),
				Source = txtSource.Text.Trim(),
				EmbeddedCode = txtEmbeddedCode.Text.Trim(),
				UserName = txtUserName.Text.Trim(),
				UserUrl = txtUserUrl.Text.Trim(),
				AddedTime = DateTime.Now,
				IsDeleted = false,
			};

			db.TUserRecommends.DeleteOnSubmit(commend);
			db.TVideos.InsertOnSubmit(video);
			db.SubmitChanges();

			Response.Redirect("UserRecommend.aspx");
		}
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table>
<tr><td>标题：</td><td><asp:TextBox ID="txtTitle" runat="server" Width="420"></asp:TextBox></td></tr>
<tr><td>简介：</td><td><asp:TextBox ID="txtDescription" runat="server" Width="420" Height="120" TextMode="MultiLine"></asp:TextBox></td></tr>
<tr><td>页面地址：</td><td>
<asp:TextBox ID="txtSource" runat="server" Width="380"></asp:TextBox>
<asp:HyperLink ID="lnkSource" runat="server" Text="查看" Target="_blank"></asp:HyperLink>
</td></tr>
<tr><td>嵌入代码：</td><td><asp:TextBox ID="txtEmbeddedCode" runat="server" Width="420" Height="120" TextMode="MultiLine"></asp:TextBox></td></tr>
<tr><td></td><td></td></tr>
<tr><td>用户名：</td><td><asp:TextBox ID="txtUserName" runat="server" Width="420"></asp:TextBox></td></tr>
<tr><td>用户连接地址：</td><td>
<asp:TextBox ID="txtUserUrl" runat="server" Width="380"></asp:TextBox>
<asp:HyperLink ID="lnkUserUrl" runat="server" Text="查看" Target="_blank"></asp:HyperLink>
</td></tr>
</table>
<asp:Button ID="btnAdd" runat="server" Text="添加到视频库" onclick="btnAdd_Click" />
</asp:Content>

